package com.bosssoft.cart.controller;

import com.alibaba.fastjson.JSON;
import com.bosssoft.cart.mapper.BookMapper;
import com.bosssoft.cart.mapper.ShopCartMapper;
import com.bosssoft.cart.pojo.Books;
import com.bosssoft.cart.pojo.ShopCart;
import com.bosssoft.cart.service.BookService;
import com.bosssoft.cart.service.ShopCartService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.awt.print.Book;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

@RestController
public class CartController {

    @Autowired
    private ShopCartService shopCartService;

    /**
     * 获取购物车列表
     * @return 购物车
     */
    @GetMapping("/cart/all")
    public  String queryCart(){
        return JSON.toJSONString(shopCartService.queryCartList());
    }

    /**
     * 根据id从购物车移除商品
     * @param bookID 商品id
     */
    @GetMapping("/cart/add/{bookID}")
    public  void  addIntoCart(@PathVariable("bookID") int bookID,HttpSession session){

         shopCartService.addIntoCart(bookID,session);

    }

    /**
     * 根据id将商品添加进购物车
     * @param bookID 商品id
     */
    @GetMapping("/remove/{bookID}")
    public  void  removeFromCart(@PathVariable("bookID") int bookID,HttpSession session){
        shopCartService.removeFromCart(bookID, session);

    }
}
